package com.dd.cloud.user.service.consule.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.common.interceptor.UserInterceptor;
import com.dd.cloud.common.vo.PageVo;
import com.dd.cloud.user.entity.consult.WebSocketPrivateGroup;
import com.dd.cloud.user.mapper.consult.WebSocketPrivateGroupMapper;
import com.dd.cloud.user.req.consult.WebSocketPrivateGroupAdminPageReq;
import com.dd.cloud.user.res.consult.WebSocketPrivateGroupAdminPageRes;
import com.dd.cloud.user.service.consule.IWebSocketPrivateGroupService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * webSocket私聊群 服务实现类
 * </p>
 *
 * @author czg
 * @since 2024-02-20
 */
@Service
public class WebSocketPrivateGroupServiceImpl extends ServiceImpl<WebSocketPrivateGroupMapper, WebSocketPrivateGroup> implements IWebSocketPrivateGroupService {
    /**
     * 查询沟通记录列表 分页
     *
     * @param req
     * @return
     */
    @Override
    public PageVo<WebSocketPrivateGroupAdminPageRes> queryWebSocketPrivateGroupAdminPage(WebSocketPrivateGroupAdminPageReq req) {
        if (req.getStatus() == null) {
            req.setStatus(1);
        }
        if (req.getStatus() == 2) {
            req.setAdminId(UserInterceptor.getLoginUserInfo().get().getId());
        }
        PageVo<WebSocketPrivateGroupAdminPageRes> pageVo = req.pageVoPojo();
        pageVo = getBaseMapper().queryWebSocketPrivateGroupAdminPage(pageVo, req);
        Map<String, Integer> map = new HashMap<>(3);
        QueryWrapper<WebSocketPrivateGroup> qw = new QueryWrapper<>();
        qw.lambda().eq(WebSocketPrivateGroup::getStatus, 1);
        map.put("status1", count(qw));
        qw.clear();
        qw.lambda().eq(WebSocketPrivateGroup::getStatus, 2);
        qw.lambda().eq(WebSocketPrivateGroup::getAdminUserId, UserInterceptor.getLoginUserInfo().get().getId());
        map.put("status2", count(qw));
        qw.clear();
        qw.lambda().eq(WebSocketPrivateGroup::getStatus, 3);
        qw.lambda().eq(WebSocketPrivateGroup::getAdminUserId, UserInterceptor.getLoginUserInfo().get().getId());
        map.put("status3", count(qw));
        pageVo.setExtend(map);
        return pageVo;
    }
}
